<%-- 
    Document   : CoversorDeMassa
    Created on : 16/12/2011, 23:00:19
    Author     : Usuario
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Hello World!</h1>
              <form name="Entrada" action="">
            <br><BR>
            Quero Converter: <input type="text" name="Entrada" value=<%=request.getParameter("Entrada")%> />
            <select name="TipoDeMassa1">
                <option>Tonelada</option>
                <option>Kilonewton</option>
                <option>Quilograma</option>
                <option>Hectograma</option>
                <option>Grama</option>
                <option>Quilate</option>
                <option>Centigrama</option>
                <option>Miligrama</option>
                <option>libra</option>
                <option>onça</option>
                <option>libra troy</option>
                <option>onça troy</option>
              </select>
            <input type="submit" value="Converter" name="" />

                        <br><BR>

            <select name="TipoDeMassa2">
                <option>Tonelada</option>
                <option>Kilonewton</option>
                <option>Quilograma</option>
                <option>Hectograma</option>
                <option>Grama</option>
                <option>Quilate</option>
                <option>Centigrama</option>
                <option>Miligrama</option>
                <option>libra</option>
                <option>onça</option>
                <option>libra troy</option>
                <option>onça troy</option>
              </select>
                    </form>
             <%  try {
                        if (request.getParameter("Entrada") != null) {

                                Double numero = Double.parseDouble(request.getParameter("Entrada"));

        %>
        <%
        String a = "";
        String nome1 = a ;
        double fator = 100 ;
        double fator1 = 1;
        double fator2 = 1;
        double res = 100;
	if (request.getParameter("TipoDeMassa1").equals("Tonelada")) fator = 1000;
        if (request.getParameter("TipoDeMassa1").equals("Kilonewton")) fator = 101.93;
        if (request.getParameter("TipoDeMassa1").equals("Quilograma")) fator = 1;
        if (request.getParameter("TipoDeMassa1").equals("Hectograma")) fator = 0.1;
	if (request.getParameter("TipoDeMassa1").equals("Grama")) fator = 0.001;
	if (request.getParameter("TipoDeMassa1").equals("Quilate")) fator = 0.0002;
        if (request.getParameter("TipoDeMassa1").equals("Centigrama")) fator = 0.00001;
        if (request.getParameter("TipoDeMassa1").equals("Miligrama")) fator = 0.000001;
        if (request.getParameter("TipoDeMassa1").equals("libra")) fator = 0.4535924;
        if (request.getParameter("TipoDeMassa1").equals("onça")) fator = 0.02834954;
	if (request.getParameter("TipoDeMassa1").equals("libra troy")) fator = 0.373241;
	if (request.getParameter("TipoDeMassa1").equals("onça troy")) fator = 0.031103;
	fator1 = fator;


        if (request.getParameter("TipoDeMassa2").equals("Tonelada")) fator = 1000;
        if (request.getParameter("TipoDeMassa2").equals("Kilonewton")) fator = 101.93;
        if (request.getParameter("TipoDeMassa2").equals("Quilograma")) fator = 1;
        if (request.getParameter("TipoDeMassa2").equals("Hectograma")) fator = 0.1;
	if (request.getParameter("TipoDeMassa2").equals("Grama")) fator = 0.001;
	if (request.getParameter("TipoDeMassa2").equals("Quilate")) fator = 0.0002;
        if (request.getParameter("TipoDeMassa2").equals("Centigrama")) fator = 0.00001;
        if (request.getParameter("TipoDeMassa2").equals("Miligrama")) fator = 0.000001;
        if (request.getParameter("TipoDeMassa2").equals("libra")) fator = 0.4535924;
        if (request.getParameter("TipoDeMassa2").equals("onça")) fator = 0.02834954;
	if (request.getParameter("TipoDeMassa2").equals("libra troy")) fator = 0.373241;
        if (request.getParameter("TipoDeMassa2").equals("onça troy")) fator = 0.031103;


	fator2 = fator;
        res = numero * (fator1/fator2);



%>
<br><br><h2>O resultado é:<%= res%></h2>

 <%
              }
          } catch (Exception e) {%><br><br><h1>Verifique se o campo foi preenchido corretamente</h1><%                      }
        %>


    </body>
</html>


